package scantask.client.threeDObjects;

import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.layers.AirspaceLayer;

import java.awt.Color;

import scantask.client.presentationLayer.FunctionalityPanel;
import scantask.client.presentationLayer.Presentation;
import scantask.client.threeDObjects.exceptions.Illegal3DObjectParameter;

public class Box extends LeafPolygone {
	
	private double _width;

	public Box(Color color, double xCenter, double yCenter, double buttom,
			double up, int angle, double width, double value) throws Illegal3DObjectParameter {
		super(color, xCenter, yCenter, buttom, up, angle, value);
		
		if (width <= 0) {
			scantask.client.utilities.logging.SingletonLogger.getLogger().warning("Fail illegal width entered");
			throw new Illegal3DObjectParameter();
		}
		
		this._width = width;
		
	}

	@Override
	public ComponentPolygone clone() {
		ComponentPolygone ans = null;
		try {
			ans = new Box(this._color, this._xCenter, this._yCenter,
					this._buttom, this._up, this._angle, this._width, this._value);
		} catch (Illegal3DObjectParameter e) {
			// AdirD - Impossible exception
		}
		
		return ans;
	}

//	@Override
//	public void draw(AirspaceLayer layer) {
//		// TODO Auto-generated method stub
//		
//	}
	
	@Override
	public void init3DObject(AirspaceLayer layer){
		super.init3DObject(layer);
		this._shape3D = new gov.nasa.worldwind.render.airspaces.Box(
				LatLon.fromDegrees((this._yCenter + (this._width/200000)), this._xCenter),
				LatLon.fromDegrees((this._yCenter - (this._width/200000)), this._xCenter),
				(this._width/2), (this._width/2));
		this._shape3D.setAltitudes(this._buttom, this._up + Math.abs(this._up - this._buttom)* FunctionalityPanel.DEFAULT_FACTOR);
		Presentation.AppFrame.setAttr(this._shape3D, this._color, Color.ORANGE);
//		this.setDescription("Measurement value is: " + this._value);
	}

}
